<?php

// #################################################################### ||
// #                                                                  # ||
// #   MySmartBB Version 1.5.0         http://www.MySmartBB.com       # ||
// #==================================================================# ||
// #   filename : faq.php                                             # ||
// #==================================================================# ||
// #   MySmartBB Royal 1.1.0                                          # ||
// #   BY : Royal Developers Team                                     # ||
// #                                                                  # ||
// #################################################################### ||



// ** General definitions **

     define('NOT_IN_INDEX',0);
     include('common.php');

	 if(!isset($_GET["faq"]) or empty($_GET["faq"]) or $_GET["faq"] != 1 and $_GET["faq"] != "show" and $_GET["faq"] != "search")
		 {
			 echo"<script>location.href='faq.php?faq=1'</script>";
		 }
	 if ($_GET['faq'] == 1)
     {
	
	$SF->html_title_page('الاسئلة الشائعة -(Powered By MySmartBB Universal)');
	$faq_query          = $DB->sql_query("SELECT * FROM " . $db_prefix . "faq ORDER BY faq_order ASC  ");
	$faq_row = array();
	while ($faq_row2 = $DB->sql_fetch_array($faq_query))
		{
 		     $faq_row[] = $faq_row2;
		     $Smarty->assign('faq_row',$faq_row);
		}
	$Smarty->assign('path_bar','الاسئلة الشائعة');
 	$Smarty->display('path-bar.tpl');
	$Smarty->display('faq_index.tpl');
      }
	 if ($_GET['faq'] == "show"){
	   $Smarty->assign('path_bar','<a href="faq.php?faq=1">الاسئلة الشائعة</a>');
 	  $id = intval($_GET['id']);  
  	       $fshow_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "faq WHERE id='$id'");
   	      $fshow_num   = $DB->sql_num_rows($fshow_query);
   	      $fshow_row   = $DB->sql_fetch_array($fshow_query);
      	   if ($fshow_num <= 0)
      		   {
	 $SF->error ('الرابط المتبع خاطئ');
        		 }
    	     $SF->html_title_page($SF->SafeOutPuts($fshow_row['title']) . ' - (Powered By MySmartBB Royal)');
     	    $text = $SF->SafeOutPuts($fshow_row['text']);
     	    $text = stripslashes($text);
		     $text = nl2br($text);
		 if(isset($_GET["highlight"]) and !empty($_GET["highlight"])) {
		 $word = $_GET["highlight"];
		 $text = str_replace($word,'<strong><font color="red">'.$word.'</font></strong>',$text);
		 }
    	     $Smarty->assign('text',$text);
     	    $Smarty->assign_by_ref('fshow_row',$fshow_row);            
     	    $Smarty->display('path-bar.tpl');
      	   $Smarty->display('faq.tpl');
	 }
   	  if($_GET["faq"] == "search") {
	$SF->html_title_page('الاسئلة الشائعة - (Powered By MySmartBB Universal)');
	 if($_GET["start"] == 1) {
	 $word = trim(htmlspecialchars($_POST["word"]));
 	 if (empty($word))
        		 { $SF->error('يرجى تعبئة كافة المعلومات');}
	 $search_query = $DB->sql_query("select * from ".$db_prefix."faq where (text LIKE '%".$SF->SafeSQL($word)."%') or (title LIKE '%".$SF->SafeSQL($word)."%') or (faq_describe LIKE '%".$SF->SafeSQL($word)."%') order by id asc");
	 $rows_num     = $DB->sql_num_rows($search_query);
	 if($rows_num == 0) { $SF->error('لم يتم العثور على نتائج .. يُرجى البحث بصيغة مختلفة'); }
	 if($rows_num > 0)  {
	 $search_result = array();
	 while($search_results = $DB->sql_fetch_array($search_query)) {
	 $search_result[] = $search_results;
	 $Smarty->assign("search_result",$search_result);
	 }
	 $Smarty->assign("word",$word);
	 $Smarty->assign('path_bar','<a href="faq.php?faq=1">الاسئلة الشائعة</a>');
 	$Smarty->display('path-bar.tpl');
	 $Smarty->display("faq_search-results.tpl"); 
	 }
	 }
	 }
         $SF->FastMove();
         $Smarty->display('footer.tpl');
?>